package com.gitee.hermer.engine.jars.demo.core.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import org.springframework.aop.framework.AopContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.atomikos.icatch.CompositeCoordinator;
import com.atomikos.icatch.CompositeTransaction;
import com.atomikos.icatch.config.Configuration;
import com.atomikos.icatch.provider.ConfigProperties;
import com.atomikos.recovery.TxState;
import com.gitee.hermer.boot.jee.commons.exception.ErrorCode;
import com.gitee.hermer.boot.jee.commons.exception.PaiUException;
import com.gitee.hermer.boot.jee.commons.log.UtilsContext;
import com.gitee.hermer.boot.jee.commons.utils.StringUtils;
import com.gitee.hermer.engine.jars.core.eventbus.EventType;
import com.gitee.hermer.engine.jars.core.eventbus.annotate.OnEvent;
import com.gitee.hermer.engine.jars.demo.core.po.TestPO;
import com.gitee.hermer.engine.jars.demo.core.po.TestPOExample;
import com.gitee.hermer.engine.jars.demo.core.service.ITestService;

import house.jc.engine.execute.sdk.annotation.EngineComponent;
import house.jc.engine.execute.sdk.annotation.EngineJob;


@Service
@Transactional(readOnly=false)
@EngineComponent
public class TestServiceImpl3 extends UtilsContext{
	
	
//	@Autowired
//	private TestDao dao;
	
	@EngineJob(jobMethod = "updateTestPO5")
	public void updateTestPO5(){
		
	}
	
	private Integer count = 0;
	
	
	@OnEvent(eventName="wcs.location.notify",eventType=EventType.QUEUE)
	public void updateTestPO6(Integer i,Integer e){
		synchronized (count) {
			count -= i+e;
		}
	}
	
	@OnEvent(eventName="wcs.location.notify",eventType=EventType.BROADCAST)
	public void updateTestPO7(Integer i,Integer e){
		synchronized (count) {
			count += i+e;
		}
	}
	@OnEvent(eventName="wcs.location.notify",eventType=EventType.BROADCAST)
	public void updateTestPO8(Integer i,Integer e){
		synchronized (count) {
			count += i+e;
		}
	}
	
	public Integer getCount() {
		return count;
	}
	
//	@Transactional
//	public void updateTestPO2(){
//		TestPOExample example = new TestPOExample();
//		example.createCriteria().andCreateOwnerEqualTo("admin");
//		TestPO record = new TestPO();
//		String code = StringUtils.getRandomString(5);
//		error(code);
//		record.setCode(code);
//		TestPO temp = (TestPO) dao.selectByExample(example).get(0);
//		example =  new TestPOExample();
//		example.createCriteria().andIdEqualTo(temp.getId());
//		dao.updateByExample(record, example);
//	}
//	
//	@Transactional
//	public void updateTestPO3(){
//		TestPOExample example = new TestPOExample();
//		example.createCriteria().andCreateOwnerEqualTo("admin");
//		TestPO record = new TestPO();
//		String code = StringUtils.getRandomString(5);
//		error(code);
//		record.setCode(code);
//		TestPO temp = (TestPO) dao.selectByExample(example).get(1);
//		example =  new TestPOExample();
//		example.createCriteria().andIdEqualTo(temp.getId());
//		dao.updateByExample(record, example);
//	}
//	
	
	
	
	
}
